package org.bot.socket.auth;

import org.bot.socket.config.SocketConfig;
import org.bot.socket.impl.SocketClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.net.URISyntaxException;
import java.util.Objects;

/**
 * @Author: 沧月
 * @Date: 2023/12/16 20:23
 * @Description: 描述
 */

public class LoginBotServer {

    public static void login() {
        SocketConfig socketConfig = CertificateManage.readCertificate();
        String mainNetworkInterfaceMac = MainNetworkInterfaceMAC.getMainNetworkInterfaceMac();

        if (socketConfig.isStatus()) {
            if (!Objects.equals(socketConfig.getMac(), mainNetworkInterfaceMac)) {
                throw new RuntimeException("当前设备暂未授权使用!");
            }
        } else {
            socketConfig.setMac(mainNetworkInterfaceMac);
        }
        try {
            SocketClient.build(socketConfig).connect();
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
}
